package com.aop.example.config;

import com.aop.example.interceptor.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebConfig implements WebMvcConfigurer {

    @Autowired
    private MyInterceptor authorityInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(new MyInterceptor());
        // 可以添加多个Interceptor，并指定它们的拦截路径和排除路径
        registry.addInterceptor(authorityInterceptor).excludePathPatterns(
                "/user/login/{username}/{password}",
//                "/user/register",
                "/doc.html#/home/**", // 排除knife4j的主页面，可能还有其他静态资源文件
                "/swagger-resources/**", // 排除Swagger资源文件
                "/v2/api-docs/**", // 排除Swagger API文档端点
                "/webjars/**" // 排除webjars中的静态资源，比如Swagger UI的依赖
        );
    }
}
